/* GUI CONVERTED from rewoiq05.p (converter v1.76) Thu Apr 11 05:26:25 2002 */
/* rewoiq05.p - REPETITIVE WIP STATUS INQUIRY                                 */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.25 $                                                          */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*                */
/* REVISION: 7.3      LAST MODIFIED: 02/14/95   BY: srk *G0DS*                */
/* REVISION: 7.3      LAST MODIFIED: 03/29/95   BY: dzn *F0PN*                */
/* REVISION: 7.3      LAST MODIFIED: 06/04/96   BY: jym *G1W6*                */
/* REVISION: 7.4      LAST MODIFIED: 07/29/96   BY: *G29Z* Julie Milligan     */
/* REVISION: 7.4      LAST MODIFIED: 01/17/97   BY: *G2JV* Julie Milligan     */
/* REVISION: 8.5      LAST MODIFIED: 05/05/97   BY: *J1QK* Julie Milligan     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 08/25/98   BY: *J2XF* Raphael T.         */
/* REVISION: 9.0      LAST MODIFIED: 10/27/98   BY: *J2QJ* Mugdha Tambe       */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 04/21/99   BY: *L0DY* G.Latha            */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates         */
/* REVISION: 9.1      LAST MODIFIED: 11/16/99   BY: *J3MC* Jyoti Thatte       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 07/25/00   BY: *N0GQ* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 09/05/00   BY: *L13H* Mark Christian     */
/* Revision: 1.24      BY: Robin McCarthy        DATE: 10/01/01  ECO: *P025*  */
/* $Revision: 1.25 $   BY: Jean Miller           DATE: 04/09/02  ECO: *P058*  */

/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*V8:ConvertMode=Report                                                       */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "b+ "}

define variable cumwo_lot as character no-undo.
define variable eff_date like tr_effdate no-undo.
define variable site like op_site no-undo.
define variable part like pt_part no-undo.
define variable line like ln_line no-undo.
define variable bom_code like wo_bom_code label "BOM" no-undo.
define variable routing like wo_routing label "Routing" no-undo.
define variable op like ro_op no-undo.
define variable msg_type as integer no-undo.
define variable i as integer no-undo.
define variable first_op like mfc_logical no-undo.
define variable global_addr_ok like mfc_logical no-undo.
define variable moved_in like wr_qty_cummove
   label "Cum Moved In" no-undo.
define variable inque_label as character format "x(12)"
   label "Input Queue" no-undo.
define variable outque_label as character format "x(12)"
   label "Output Queue" no-undo.
define variable rejque_label as character format "x(12)"
   label "Reject Queue" no-undo.
define variable inque_value as decimal format "->>>>>>>>9.9<<<<<<<<"
   label "Quantity" no-undo.
define variable outque_value as decimal format "->>>>>>>>9.9<<<<<<<<"
   label "Quantity" no-undo.
define variable rejque_value as decimal format "->>>>>>>>9.9<<<<<<<<"
   label "Quantity" no-undo.

define variable beginquelabel  as character no-undo.
define variable procinlabel    as character no-undo.
define variable procoutlabel   as character no-undo.
define variable curquelabel    as character no-undo.
define variable movedinlabel   as character no-undo.
define variable movedoutlabel  as character no-undo.
define variable rejectinlabel  as character no-undo.
define variable rejectoutlabel as character no-undo.
define variable reworkinlabel  as character no-undo.
define variable reworkoutlabel as character no-undo.
define variable scraplabel     as character no-undo.
define variable adjustlabel    as character no-undo.
define variable schedwo_lot as character no-undo.
define variable ok like mfc_logical no-undo.
define variable prompt-routing like mfc_logical no-undo.
define variable o_cancel like mfc_logical no-undo.
define variable o_cancel2 like mfc_logical no-undo.
define variable h_wiplottrace_funcs as handle no-undo.

/* **********SET INITIAL VALUES*********** */
assign
   beginquelabel  = getTermLabel("BEGIN_QTY",12)
   procinlabel    = "+" + getTermLabel("PROCESSED",11)
   procoutlabel   = "-" + getTermLabel("PROCESSED",11)
   curquelabel    = getTermLabel("CURRENT_QTY",12)
   movedinlabel   = "+" + getTermLabel("MOVED_IN",11)
   movedoutlabel  = "-" + getTermLabel("MOVED_OUT",11)
   rejectinlabel  = "+" + getTermLabel("REJECTED",11)
   rejectoutlabel = "-" + getTermLabel("REJECTED",11)
   reworkinlabel  = "+" + getTermLabel("REWORKED",11)
   reworkoutlabel = "-" + getTermLabel("REWORKED",11)
   scraplabel     = "-" + getTermLabel("SCRAPPED",11)
   adjustlabel    = "-" + getTermLabel("ADJUSTED",11).

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
eff_date                colon 13
   site                        colon 40
   part                        colon 13
   pt_desc1                at 36 no-label no-attr-space
   op                        colon 13
   wr_desc                at 36 no-label no-attr-space
   line                        colon 13
   ln_desc                at 36 no-label no-attr-space
   bom_code                colon 13
   routing                colon 43
   wo_lot
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

assign
   eff_date = today
   global_addr_ok = yes.

display eff_date with frame a.

/* GET MOST RECENT WR_ROUTE RECORD CREATED AND DISPLAY DATA
 * AS INITIAL DEFAULTS*/

do i = 1 to length(global_addr):
   if substring(global_addr,i,1) < "0" or substring(global_addr,i,1) > "9"
      then global_addr_ok = no.
end.

if global_addr_ok then do:
   find wr_route where recid(wr_route) = integer(global_addr)
   no-lock no-error.

   if available wr_route then do:
      find wo_mstr where wo_lot = wr_lot no-lock.
      assign
         site = wo_site
         part = wo_part
         op = wr_op
         line = wo_line
         bom_code = wo_bom_code
         routing = wo_routing
         eff_date = wo_due_date.
      display eff_date
         site
         part
         op
         line
         bom_code
         routing
      with frame a.
   end.
   else do:
      find op_hist where recid(op_hist) = integer(global_addr)
      no-lock no-error.

      if available op_hist then do:
         /* TO AVOID PROGRESS ERROR MESSAGE "WO_MSTR    */
         /* RECORD NOT ON FILE"                         */

         for first wo_mstr
            fields(wo_bom_code wo_due_date wo_due_date
            wo_line wo_lot wo_part wo_routing
            wo_site wo_status)
            where wo_lot = op_wo_lot
         no-lock:
         end. /* FOR FIRST WO_MSTR */
         if available wo_mstr then

         assign
            site = wo_site
            part = wo_part
            op = op_wo_op
            line = wo_line
            bom_code = wo_bom_code
            routing = wo_routing
            eff_date = op_date.
         display eff_date
            site
            part
            op
            line
            bom_code
            routing
         with frame a.
      end.
   end.
end.

repeat:

   run scroll_procedure
      (output o_cancel).

   if o_cancel then leave.

   do with frame a on error undo, retry:

      update part op line with frame a
      editing:

         if frame-field = "part" then do:

            /* MFNP06.I SCROLLS THROUGH ALL ITEMS BELONGING TO            */
            /* CUMULATIVE WORK ORDERS AT SPECIFIED SITE WITH WORK ORDER   */
            /* DUE DATE GREATER OR EQUAL TO SPECIFIED EFFECTIVE DATE      */

            {mfnp06.i wo_mstr  wo_part
               "wo_site = site and wo_type = ""C"" "
               wo_part part
               wo_due_date  eff_date
               """" """"
               }

            if recno <> ? then do:

               if wo_routing <> "" or  wo_bom_code <> "" then do:
                  assign routing  = wo_routing
                     line     = wo_line
                     bom_code = wo_bom_code .
                  find first pt_mstr where pt_part = wo_part no-lock
                     no-error .
                  display wo_part @ part
                     pt_desc1
                     routing
                     bom_code
                     wo_lot   .
               end.

               else do:
                  find first pt_mstr where pt_part = input frame a part
                  no-lock no-error .

                  display wo_part @ part pt_desc1.

                  find ptp_det no-lock where ptp_part = pt_part
                     and ptp_site = site no-error.

                  if available ptp_det then do:

                     if ptp_routing > ""
                        then routing = ptp_routing.
                     else routing = "".

                     if ptp_bom_code > ""
                        then bom_code = ptp_bom_code.
                     else bom_code = "".
                  end.
                  else do:
                     routing = if pt_routing > ""
                        then pt_routing else "".

                     if pt_bom_code > ""
                        then bom_code = pt_bom_code.
                     else bom_code = "".
                  end.

                  display routing bom_code wo_lot.
               end. /* IF WO_ROUTING <> "" AND WO_BOM_CODE <> "" */

            end. /* IF RECNO <> ? */

         end.

         else
      if frame-field = "op"
            and can-find(pt_mstr where pt_part = input frame a part)
         then do:
            if recno = ? then do:

               find pt_mstr where pt_part = input frame a part
               no-lock no-error.

               find ptp_det where ptp_part = pt_part
                  and   ptp_site = site
               no-lock no-error.

               if available ptp_det then do:
                  if ptp_routing > ""
                     then routing = ptp_routing.
                  else routing = ptp_part.
               end.
               else
                  routing = if pt_routing > "" then
               pt_routing

               else "".

            end.  /* IF RECNO = ? */

            {mfnp05.i ro_det ro_routing "ro_routing = routing"
               ro_op "input frame a op"}

            if recno <> ? then do:
               display ro_op @ op ro_desc @ wr_desc.
               display "" @ line "" @ ln_desc.
            end.
         end.
         else
            if frame-field = "line" then do:

            /* MFNP07.I SCROLLS THROUGH ALL LINES SCHEDULED  FOR    */
            /* SPECIFIED ITEM AT SPECIFIED SITE                             */

            {mfnp07.i lnd_det
               line lnd_line
               site lnd_site
               part lnd_part
               """" """"
               lnd_line}

            if recno <> ? then do:

               find ln_mstr where ln_line = lnd_line
                  and   ln_site = lnd_site
               no-lock no-error.

               display ln_line @ line ln_desc.
            end.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end.

      find pt_mstr where pt_part = part no-lock no-error.

      if not available pt_mstr then do:
         /* ITEM NUMBER DOES NOT EXIST */
         {pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
         undo, retry.
      end.

      display
         pt_desc1
         "" @ ln_desc.

      /* ACCEPT BLANK PRODUCTION LINE AS VALID */
      /* INPUT IF THERE ARE NO PRODUCTION LINES DEFINED FOR THE SITE   */

      if can-find (first ln_mstr where ln_site = site)
         or line <> "" then do:

         find ln_mstr where ln_site = site and ln_line = line
         no-lock no-error.

         if not available ln_mstr then do:
            /* SITE PRODCUTION LINE DOES NOT EXIST */
            {pxmsg.i &MSGNUM=8526 &ERRORLEVEL=3}
            next-prompt line.
            undo, retry.
         end. /* IF NOT AVAILABLE LN_MSTR */

         find first lnd_det
            where lnd_line = line
            and lnd_site = site
            and lnd_part = part
            and (lnd_start <= today or lnd_start = ?)
         no-lock no-error.

         if not available lnd_det then do:
            /* ITEM NOT DEFINED ON THIS PRODUCTION LINE */
            {pxmsg.i &MSGNUM=8527 &ERRORLEVEL=3}
            next-prompt line.
            undo , retry.
         end. /* IF NOT AVAILABLE LND_DET */

         display ln_desc.

      end. /* IF AVAILABLE LN_MSTR OR LINE <> ""  */

   end.

   do with frame a on error undo, retry:
      set bom_code routing with frame a
      editing:
         if frame-field = "routing" then do:
            {mfnp05.i ptr_det ptr_part
               "ptr_part = part and ptr_site = site"
               ptr_routing "input routing"}

            if recno <> ? then do:
               display ptr_routing @ routing.
               recno = ?.
            end.
         end.
         else
            if frame-field = "bom_code" then do:

            {mfnp05.i ps_mstr ps_par yes
               ps_par "input frame a bom_code"
               }

            if recno <> ? then do:

               display ps_par @ bom_code.
               recno = ?.
            end.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end.

      {gprun.i ""wortbmv.p"" "(input part,
           input site,
           input routing,
           input bom_code,
           input 3,
           output ok,
           output prompt-routing)"}

      if not ok and prompt-routing then next-prompt routing.
      else if not ok then next-prompt bom_code.
      if not ok then undo, retry.
      if routing = "" and
         not can-find (first ro_det where ro_routing = part)
      then do:
         next-prompt routing.
         /* ROUTING DOES NOT EXISTS */
         {pxmsg.i &MSGNUM=126 &ERRORLEVEL=3}
         undo, retry.
      end.

   end.

   run get_cum_order
      (output o_cancel2).

   if o_cancel2 then undo, retry.

   hide frame detail.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "terminal"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   view frame a.

   /*GET QTY MOVED IN FROM PREVIOUS OP IF THERE IS ONE*/
   {gprun.i ""rewoiq5a.p"" "(input wr_lot,
        input wr_op,
        output moved_in,
        output first_op)"
      }

   run run-report.

   if is_wiplottrace_enabled() then do:
      run show_wiplot_data
         (input wr_lot, input wr_op, input pt_um).
   end.

   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

   /* LIST COMPLETE */
   {pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}

end.

/* * * * * * * * INTERNAL PROCEDURES * * * * * * * * * * * * * */
PROCEDURE run-report:
   do with frame detail:
      FORM /*GUI*/ 
         inque_label
         inque_value
         outque_label
         outque_value
         rejque_label
         rejque_value
      with STREAM-IO /*GUI*/  frame detail width 80 down.

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame detail:handle).

      {rewoiq05.i}
   end.

END PROCEDURE. /* run-report */

PROCEDURE show_wiplot_data:
   define input parameter lot like wr_lot no-undo.
   define input parameter op like wr_op no-undo.
   define input parameter um like pt_um no-undo.

   {gprunmo.i
      &program = ""rewoiqa.p""
      &module = "AWT"
      &param = """(input lot, input op, input um)"""}

   message.
   message.
   message.

END PROCEDURE.

PROCEDURE scroll_procedure:

   define output parameter o_cancel like mfc_logical.

   o_cancel = true.

   do with frame a on error undo, retry:
      set eff_date site with frame a
      editing:
         if frame-field = "site" then do:
            {mfnp05.i si_mstr si_site yes si_site "input frame a site"}

            if recno <> ? then do:
               display si_site @ site.
            end.
         end.
         else do:
            ststatus = stline[3].
            status input ststatus.
            readkey.
            apply lastkey.
         end.
      end.

      find si_mstr where si_site = site no-lock no-error.

      if not available si_mstr then do:
         /* SITE DOES NOT EXIST */
         {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
         next-prompt site.
         undo , retry.
      end.

   end.

   o_cancel = false.

END PROCEDURE.

PROCEDURE get_cum_order:

   define output parameter o_cancel2 like mfc_logical no-undo.

   o_cancel2 = true.

   /*FIND CUM ORDER*/
   {gprun.i ""regetwo.p"" "(input site,
        input part, input eff_date,
        input line,
        input routing,
        input bom_code,
        output cumwo_lot)"}

   if cumwo_lot = ? then do:
      /* WORK ORDER/ID DOES NOT EXIST */
      {pxmsg.i &MSGNUM=510 &ERRORLEVEL=3}
      undo, retry.
   end.
   else do:
      display cumwo_lot @ wo_lot with frame a.
      find wo_mstr where wo_lot = cumwo_lot no-lock.

      if wo_status = "c" then do:
         /* CUM ORDER IS CLOSED */
         {pxmsg.i &MSGNUM=5101 &ERRORLEVEL=3}
      end.
   end.

   find wr_route where wr_lot = cumwo_lot and wr_op = op
   no-lock no-error.
   if not available wr_route then do:
      /* OPERATION DOES NOT EXIST */
      {pxmsg.i &MSGNUM=106 &ERRORLEVEL=3}
      undo, retry.
   end.

   if not wr_milestone then do:
      /* OPERATION NOT A MILESTONE */
      {pxmsg.i &MSGNUM=560 &ERRORLEVEL=2}
   end.

   display wr_desc with frame a.

   o_cancel2 = false.

END PROCEDURE.
